package com.heima.user.controller;

import com.heima.user.domain.dto.UserLoginDto;
import com.heima.user.domain.po.User;
import com.heima.user.service.IUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController {

    private final IUserService userService;

    // 登录
    @PostMapping("/login")
    public String login(@RequestBody UserLoginDto dto){
        return userService.login(dto);
    }

    // 新增
    @PostMapping("/save")
    public boolean save(@RequestBody User user){
        return userService.save(user);
    }

    // 删除
    @DeleteMapping("/delete/{id}")
    public boolean delete(@PathVariable("id") Long id){
        return userService.removeById(id);
    }

    // 修改
    @PutMapping("/update")
    public boolean update(@RequestBody User user){
        return userService.updateById(user);
    }

    // 查询
    @GetMapping("/get/{id}")
    public User get(@PathVariable("id") Long id){
        return userService.getById(id);
    }
}
